home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / CALEN4.AML < prev    next >
Text File  |  1996-07-17  |  5KB  |  247 lines

  1. //--------------------------------------------------------------------
  2. // CALEN4.AML
  3. // Four-month Calendar, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Calen4.dox for user help)
  6. //
  7. // This macro displays a calendar window with four months, starting with
  8. // the previous month. The current day is highlighted.
  9. //
  10. // This macro also calls Cfg\Cfgintnl.x
  11. //
  12. // Usage:
  13. //
  14. // Select this macro from the Macro List (on the Macro menu), or run it
  15. // from the macro picklist <shift f12>.
  16. //--------------------------------------------------------------------
  17.  
  18. include bootpath "define.aml"
  19.  
  20. // define the colors to use
  21. constant cal_border_color   = color white       on gray
  22. constant cal_bordera_color  = color brightgreen on gray
  23. constant cal_title_color    = color brightblue  on gray
  24. constant cal_client_color   = color black       on gray
  25. constant cal_today_color    = color brightgreen on gray
  26. constant cal_control_color  = color yellow
  27.  
  28. variable year, month
  29.  
  30. // create the calendar window
  31. createwindow
  32. setframe ">b"
  33. setwinctrl '≡'
  34. setshadow 2 1
  35. sizewindow 3 4 75 20 "ad"
  36. setborder "1i"
  37. settitle "Four Month Calendar" 'c'
  38. setcolor  border_color         cal_border_color
  39. setcolor  border_flash_color   cal_bordera_color
  40. setcolor  text_color           cal_client_color
  41. setcolor  control_color        cal_control_color
  42.  
  43. // current year and month
  44. year  = getrawtime [1:4]
  45. month = getrawtime [5:2]
  46.  
  47. // keep this object resident
  48. resident ON
  49. settype "win"
  50.  
  51. constant daynames = 1
  52. constant monthnames = 2
  53.  
  54. // get day and month names
  55. names = runmacro (bootpath "cfg\\cfgintnl.x") '' 'n'
  56. months = names.monthnames
  57. dayheader = ' '
  58. for i = 1 to 7 do
  59.   dayheader = dayheader + names.daynames [i][1..3] + '  '
  60. end
  61.  
  62. // function to redraw the calendar at x,y on the screen
  63. private function draw (x y)
  64.   variable monthdays
  65.  
  66.   // save the x coordinate
  67.   xleft = x
  68.  
  69.   // set the calendar title based on the year and month
  70.   title = months [month] + " " + year
  71.  
  72.   writestr '' : ((35 - length title) / 2) + title:-35
  73.           cal_border_color x y
  74.  
  75.   y = y + 1
  76.  
  77.   // get the day in which the year starts using a perpetual
  78.   // calendar (0-6, 0=sunday)
  79.   startday = "5012356013456123460124560234" [year mod 28 + 1]
  80.  
  81.   // string indicating the days over 28 for each month
  82.   over28 = concat (if? (not (year mod 4)) "31" "30") "3232332323"
  83.  
  84.   // get total days in the month
  85.   maxdays = 28 + over28 [month]
  86.  
  87.   // get the number of days in previous months
  88.   for i = 1 to month - 1 do
  89.     monthdays = monthdays + 28 + over28 [i]
  90.   end
  91.  
  92.   // calculate the starting day for the month (0-6, 0=sunday)
  93.   startday = (startday + monthdays) mod 7
  94.  
  95.   // set 'today' to today's day number if it's the right
  96.   // year and month
  97.   rawtime = getrawtime
  98.   today = if rawtime [5:2] == month and rawtime [1:4] == year then
  99.             rawtime [7:2]
  100.           end
  101.  
  102.   // draw the days header
  103.   writestr dayheader cal_title_color x y
  104.   y = y + 1
  105.  
  106.   // move the video cursor to the start-day position
  107.   daystr = '':(startday * 5)
  108.   xrem = 0
  109.   yfirst = y
  110.  
  111.   // write the calendar body
  112.   for day = 1 to maxdays do
  113.  
  114.     if length daystr + xrem >= 35 then
  115.       writestr daystr cal_client_color x y
  116.       x = xleft
  117.       y = y + 1
  118.       daystr = ''
  119.       xrem = 0
  120.     end
  121.  
  122.     // highlight today
  123.     if day == today then
  124.       if daystr then
  125.         writestr daystr cal_client_color x y
  126.       end
  127.       todaystr = concat ' ' day:3 ' '
  128.       writestr todaystr cal_today_color xleft + length daystr y
  129.       xrem = length daystr + length todaystr
  130.       x = x + xrem
  131.       daystr = ''
  132.     else
  133.       daystr = concat daystr ' 'day:3 ' '
  134.     end
  135.  
  136.   end
  137.  
  138.   // write last incomplete calendar line, if any
  139.   if daystr then
  140.     writestr daystr:-35 cal_client_color x y
  141.     y = y + 1
  142.   end
  143.  
  144.   // write last blank line, if any
  145.   if y - yfirst < 6 then
  146.     writestr '':35 cal_client_color x y
  147.   end
  148.  
  149.  
  150.   // set month and year for next time around
  151.   month = month + 1
  152.   if month > 12 then
  153.     month = 1
  154.     year = year + 1
  155.   end
  156.  
  157. end
  158.  
  159. // draw four calander windows
  160. private function draw4
  161.   fillrect (getviewcols) (getviewrows) ' ' 1 1
  162.  
  163.   month2 = month
  164.   year2 = year
  165.  
  166.   draw  1  1
  167.   draw 38  1
  168.   draw  1 10
  169.   draw 38 10
  170.  
  171.   month = month2
  172.   year = year2
  173. end
  174.  
  175. // get the current year and month
  176. year  = getrawtime [1:4]
  177. month = getrawtime [5:2]
  178.  
  179. // get the previous month
  180. month = month - 1
  181. if not month then
  182.   month = 12
  183.   year = year - 1
  184. end
  185.  
  186. draw4
  187.  
  188. event <destroy>
  189.   // call 'close' in object 'win'
  190.   close
  191. end
  192.  
  193. // macro help
  194. macrofile = arg 1
  195. key <f1>
  196.   helpmacro macrofile
  197. end
  198.  
  199. function "≡"  destroyobject
  200. key <esc>     destroyobject
  201.  
  202. // forward one month
  203. key <pgdn>
  204.   month = month + 1
  205.   if month > 12 then
  206.     month = 1
  207.     year = year + 1
  208.   end
  209.   draw4
  210. end
  211.  
  212. // backward one month
  213. key <pgup>
  214.   month = month - 1
  215.   if not month then
  216.     month = 12
  217.     year = year - 1
  218.   end
  219.   draw4
  220. end
  221.  
  222. // goto january
  223. key <ctrl pgup>
  224.   month = 1
  225.   draw4
  226. end
  227.  
  228. // goto december
  229. key <ctrl pgdn>
  230.   month = 12
  231.   draw4
  232. end
  233.  
  234. // forward one year
  235. key <right>
  236.   year = year + 1
  237.   draw4
  238. end
  239.  
  240. // backward one year
  241. key <left>
  242.   if year then
  243.     year = year - 1
  244.   end
  245.   draw4
  246. end
  247.